package day20171213;

import java.io.File;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {

        List<String> list = new ArrayList<>(); //用来存放每一个学生的学号

        File file = new File("F:\\java"); //所有文件的存放地址
        String[] files = file.list();
        for(String f : files) {
            String s = f.substring(21,25);  //提取学生的学号信息
            list.add(s);
        }  //取得每一个人的学号并放入list集合中

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");    //加载驱动程序
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection connection = null;
        Statement statement = null;

        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC", "root", "193749");
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT * FROM  student");

            while (resultSet.next() == true) {
                String s = resultSet.getString(1);

                if(list.contains(s)) {  //如果list集合中包含有数据库中的学生的学号，则该学生交了，否则打印该学生未交。

                }else {
                    System.out.println(resultSet.getString(2) + "未交");
                }
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                connection.close();
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(list.size() == 4) {
            System.out.println("作业已交齐");
        }
    }
}
